package com.ruoyi.web.controller.liangshi;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.liangshi.domain.ArchItem;
import com.ruoyi.liangshi.domain.BizKcKsc;
import com.ruoyi.liangshi.service.IArchItemService;
import com.ruoyi.liangshi.service.IBizKcKscService;
import com.ruoyi.liangshi.vo.query.*;
//import com.ruoyi.web.task.BiBsKscTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LiuJin
 * @Date：Create in 2023-11-18 19:14
 * @Description
 */
@RestController
@RequestMapping("/liangshi/kcksc")
public class KcKscController extends BaseController {

    @Autowired
    private IBizKcKscService kcKscService;

    @Autowired
    private IArchItemService atchItemService;

    //@Autowired
    //private BiBsKscTask biBsKscTask;

    /**
     * 根据订单编号获取菜品列表
     * @param bsId
     * @return
     */
    @GetMapping("/getKscListByBsId")
    public AjaxResult getKscListByBsId(@RequestParam("bsId")Long bsId){
        List<BizKcKsc> list = kcKscService.lambdaQuery().eq(BizKcKsc::getBsId, bsId).list();
        for (BizKcKsc kcKsc : list) {
            ArchItem atchItem = atchItemService.getById(kcKsc.getItemId());
            if(atchItem==null){
                kcKsc.setItemName("未知");
            }else {
                kcKsc.setItemName(atchItem.getName());
            }


        }
        AjaxResult success = success();
        success.put("rows",list);
        return success;
    }

    /**
     * 根据日期时间获取订单菜品列表
     * @param shopId
     * @param date
     * @param shift
     * @param time
     * @return
     */
    @GetMapping("/getKscAndArchItemInfoByDate")
    public TableDataInfo getKscAndArchItemInfoByDate(@RequestParam(value = "shopId",required = false)Long shopId,
                                                     @RequestParam("date") String date,
                                                     @RequestParam(value = "shift",required = false)String shift,
                                                     @RequestParam(value = "time",required = false)String time){
        startPage();
        List<BizKscItemInfoVo> kscAndArchItemInfoByDate = kcKscService.getKscAndArchItemInfoByDate(shopId, shift,date, time);
        return getDataTable(kscAndArchItemInfoByDate);
    }

    @GetMapping("/getKscItemTypeDataInfo")
    public AjaxResult getKscItemTypeDataInfo(OrderAndKscCommonQueryVo orderAndKscCommonQueryVo){
        KscItemTypeDataInfoVo kscItemTypeDataInfo = kcKscService.getKscItemTypeDataInfo(orderAndKscCommonQueryVo);
        AjaxResult success = success();
        success.put("data",kscItemTypeDataInfo);
        return success;
    }

    @GetMapping("/getMealStatData")
    public TableDataInfo getMealStatData(OrderAndKscCommonQueryVo orderAndKscCommonQueryVo){
        startPage();
        List<BiMealStatDataVo> mealStatData = kcKscService.getMealStatData(orderAndKscCommonQueryVo);
        return getDataTable(mealStatData);
    }
    @GetMapping("/getMealTrendChartData")
    public AjaxResult getMealTrendChartData(OrderAndKscCommonQueryVo orderAndKscCommonQueryVo){
        List<BiKscMealTrendChartDataVo> mealTrendChartData = kcKscService.getMealTrendChartData(orderAndKscCommonQueryVo);
        AjaxResult success = success();
        success.put("data",mealTrendChartData);
        return success;
    }
    @GetMapping("/getMonthTimeOutInfo")
    public AjaxResult getMonthTimeOutInfo(OrderAndKscCommonQueryVo orderAndKscCommonQueryVo){
        AjaxResult success = success();
        success.put("data",kcKscService.getMonthTimeOutInfo(orderAndKscCommonQueryVo));
        return success;
    }
    @GetMapping("/getDayTimeOutInfo")
    public AjaxResult getDayTimeOutInfo(OrderAndKscCommonQueryVo orderAndKscCommonQueryVo){
        AjaxResult success = success();
        success.put("data",kcKscService.getDayTimeOutInfo(orderAndKscCommonQueryVo));
        return success;
    }

    //@GetMapping("/test")
    //public void test(){
    //    biBsKscTask.syncBiBsKscData();
    //    biBsKscTask.syncBiBsKscHourData();
    //    biBsKscTask.syncBiBsKscDayData();
    //    biBsKscTask.syncBiBsKscMonthData();
    //}
}
